package com.altorithm;

/**
 * @Classname InsertSort
 * @Date 2019/9/25 10:25
 * @auther by hqy
 */
public class InsertSort {

    public static void sort(int[] array) {

        for (int i = 1; i < array.length; i++) {
            int insertValue = array[i];
            int insertIndex = i;
            for (int j = i - 1; j >= 0; j--) {
                if (array[j] > insertValue) {
                    insertIndex = j;
                    array[j + 1] = array[j];
                }
            }
            if (insertIndex != i) {
                array[insertIndex] = insertValue;
            }

        }
    }
}
